package planit.view;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import planit.controller.ControllerFactory;
import planit.controller.ControllerFactory.ControllerType;


/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
@SuppressWarnings("serial")
public class PersonDialog extends javax.swing.JDialog {

	{
		// Set Look & Feel
		try {
			javax.swing.UIManager
			.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private JPanel jPanel1;
	private JLabel jLabel3;
	private JButton jButton1; 
	private AbstractAction cancelAction;
	private JButton jButton2;
	private JTextField emailField;
	private JTextField telephoneField;
	private JLabel jLabel2;
	private JTextField nameField;
	private JLabel jLabel1;

	public PersonDialog() {
		super();
		initGUI();
	}

	private void initGUI() {
		try {
			{
				this.setPreferredSize(new java.awt.Dimension(260, 177));
			}
			{
				jPanel1 = new JPanel();
				getContentPane().add(jPanel1, BorderLayout.CENTER);
				jPanel1.setPreferredSize(new java.awt.Dimension(260, 177));
				jPanel1.setLayout(null);
				jPanel1.setSize(260, 177);
				{
					jLabel1 = new JLabel();
					jPanel1.add(jLabel1);
					jLabel1.setText("Full Name");
					jLabel1.setBounds(14, 9, 60, 16);
				}
				{
					nameField = new JTextField();
					jPanel1.add(nameField);
					nameField.setBounds(80, 6, 157, 29);
				}
				{
					jLabel2 = new JLabel();
					jPanel1.add(jLabel2);
					jLabel2.setText("Telephone");
					jLabel2.setBounds(12, 44, 62, 16);
				}
				{
					telephoneField = new JTextField();
					jPanel1.add(telephoneField);
					telephoneField.setBounds(80, 41, 157, 29);
				}
				{
					jLabel3 = new JLabel();
					jPanel1.add(jLabel3);
					jLabel3.setText("E-mail");
					jLabel3.setBounds(12, 80, 56, 16);
				}
				{
					emailField = new JTextField();
					jPanel1.add(emailField);
					emailField.setBounds(80, 76, 157, 29);
				}
				{
					jButton1 = new JButton();
					jPanel1.add(jButton1);
					jButton1.setAction(ControllerFactory
							.getController(ControllerType.CREATE_PERSON));
					jButton1.getAction().putValue("PersonDialog", this);
					jButton1.setText("Ok");
					jButton1.setBounds(119, 111, 43, 23);
				}
				{
					jButton2 = new JButton();
					jPanel1.add(jButton2);
					jButton2.setText("Cancel");
					jButton2.setBounds(162, 111, 70, 23);
					jButton2.setAction(getCancelAction());
				}
			}
			pack();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public String getPersonPhone() {
		return telephoneField.getText();
	}

	public String getPersonMail() {
		return emailField.getText();
	}

	public String getPersonName() {
		return nameField.getText();
	}

	private AbstractAction getCancelAction() {
		if(cancelAction == null) {
			cancelAction = new AbstractAction("Cancel", null) {
				public void actionPerformed(ActionEvent evt) {
					dispose();
				}
			};
		}
		return cancelAction;
	}
}
